#!/bin/zsh
# -*-coding: latin-1;-*-

##########################################################
#
# title:     keybindings config
#
# filename:  /etc/zsh/keybindings
#
# author(s): Alessandro Molari (mola89.molarulez.com),
#            Luca Molari
#
# license:   This file is licensed under the GPLv2
#            For more informations read:
#            http://www.gnu.org/licenses/gpl-2.0.txt
#
# thanks to: zsh team (www.zsh.org)
#            grml team (grml.org)
#            Michael Prokop (mika@grml.org)
#
##########################################################



##         general options

# use emacs style per default
bindkey -e

## end of: general options


##         cursor position

# move the cursor to the previous char
#     <leftarrow>
bindkey '\e[D' backward-char
# move the cursor to the next char
#     <rightarrow>
bindkey '\e[C' forward-char

# move the cursor to the previous word
#     <ctrl>+<leftarrow>
bindkey '\e[1;5D' backward-word
# move the cursor to the next word
#     <ctrl>+<rightarrow>
bindkey '\e[1;5C' forward-word
# move the cursor to BOL
#     <home>
bindkey '\e[H' beginning-of-line
# move the cursor to EOL
#     <end>
bindkey '\e[F' end-of-line

## end of: cursor position


##         deletion

# delete the next character
#     <del>
bindkey '\e[3~' delete-char-or-list

# delete the next word
#     <ctrl>+<del>
bindkey '\e[3;5~' delete-word

# if the terminal is xterm
#     delete the previous word
#         <ctrl>+<backspace
if [ $TERM = "xterm" ]; then
    bindkey '^?' slash-backward-kill-word
fi

# jump behind the first word on the cmdline
#     <esc> 1
bindkey '\e1' jump_after_first_word

## end of: deletion


##         insertion

# enable or disable the overwrite mode
#     <ins>
bindkey '\e[2~' overwrite-mode

# insert a timestamp on the command line (yyyy-mm-dd)
#     <esc> d
bindkey '\ed' _bkdatetime

# insert the last tiped word
#     <esc> l
bindkey '\el' insert-last-typed-word

# insert a file in the current line
#     <esc> f
bindkey "\ef" insert-files

# pick item from completion menu but stay in menu for more
#     <esc> m
bindkey -M menuselect '\em' accept-and-menu-complete

# menu completion
#     <esc> c
bindkey '\ec' menu-complete

## end of: insertion


##         history

# previous item in the history
#     <uparrow>
bindkey '\e[A' up-line-or-history
# next item in the history
#     <downarrow>
bindkey '\e[B' down-line-or-history

# backward search in the history through patterns
#     <esc> p
bindkey '\ep' history-incremental-pattern-search-backward
# forward search in the history through patterns
#     <esc> n
bindkey '\en' history-incremental-pattern-search-forward

## end of: history


##         abbreviations

# expand the abbreviations
#     <space>
bindkey ' ' magic-abbrev-expand

# disable the abbraviation expansion for the next space
#     <esc> a
bindkey '\ea' no-magic-abbrev-expand

## end of: abbreviations


##         completion

# quick change directory
#     on '.' input, the slash is autocompleted when 2 '.' are inserted
bindkey . rationalise-dot

## end of: completion


##         editing

# edit the command line in $EDITOR or $VISUAL
#     <esc> e
bindkey '\ee' edit-command-line

## end of: editing


##         privileges

# put the current command line into a sudo call
#     <esc> s
bindkey "\es" sudo-command-line

## end of: privileges
